//
//  MoreDanMuViewController.m
//  A_Comic
//
//  Created by sos on 16/1/21.
//  Copyright © 2016年 sos. All rights reserved.
//

#import "MoreDanMuViewController.h"
#import "MoreDanMuTableViewCell.h"
#import <UIImageView+WebCache.h>
#import "HomePageModel.h"
#import <AFNetworking.h>
@interface MoreDanMuViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain) UITableView *tableView;//整页的tableview
@property (nonatomic,retain) NSMutableArray *dataArr;//数据数组
@end

@implementation MoreDanMuViewController
- (void)dealloc
{
    [_tableView release];
    [_dataArr release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    //创建tableview
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    [self.tableView registerClass:[MoreDanMuTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.tableView release];
    [self data];
}


-(void)data
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager GET:@"http://m.ac.qq.com/event/light_comic/action.php?action=getComicRecommend&t=1452771376922&seq=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSArray *arr = responseObject[@"data"];
        self.dataArr = [HomePageModel modelHandlerWithArray:arr];
        [self.tableView reloadData];
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
    
    
    
}
//协议方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    return self.dataArr.count;
    
    
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    MoreDanMuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    HomePageModel *m = self.dataArr[indexPath.row];
    
    [cell.qqImage sd_setImageWithURL:[NSURL URLWithString:m.artist_head]];
    cell.autorLabel.text = m.artist_name;
    cell.nameLabel.text = m.title;
    [cell.pictureImage sd_setImageWithURL:[NSURL URLWithString:m.banner_url]];
    
    return cell;
    
    
}

//cell高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 250;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    HomePageModel *m = self.dataArr[indexPath.row];
    UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://m.ac.qq.com/event/light_comic/view.html?route=recommend&id=%@&&cid=%@",m.myId,m.cid]]]];
    self.tabBarController.tabBar.hidden = YES;
    [self.view addSubview:webView];
    [webView release];
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
